package com.xxcloud.model.web;

import java.io.Serializable;

public class LimitParameter implements Serializable {

    private String word;
    private static final long serialVersionUID = -679568552984839946L;
    public static final int DEFAULT_PAGE_SIZE = 30;
    public static final int MAX_PAGE_SIZE = 5000;

    private Integer pageNo = 1;

    private Integer pageSize = DEFAULT_PAGE_SIZE;

    /**
     * 获取limit的first参数
     */
    public int getFirst() {
        if (pageNo == null || pageNo < 1) {
            pageNo = 1;
        }
        return (pageNo - 1) * getMax();
    }

    /**
     * 获取limit的max参数
     */
    public int getMax() {
        if (pageSize == null || pageSize < 1 || pageSize > MAX_PAGE_SIZE) {
            pageSize = DEFAULT_PAGE_SIZE;
        }
        return pageSize;
    }

    /**
     * 判断当前分页设置参数，是否超过最大限制条数max
     */
    public boolean isDataOverLimit(int max) {
        if (max < 0) {
            return false;
        }
        return getFirst() > max;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public static void main(String[] args) {
        LimitParameter limitParameter = new LimitParameter();
        limitParameter.setPageNo(2);
        limitParameter.setPageSize(51);
        System.out.println(limitParameter.getFirst());
        System.out.println(limitParameter.getMax());
        System.out.println(limitParameter.isDataOverLimit(10));
    }
}
